package com.leo.springbootmultithreadbasic.synchronizedkey.synchronizedmethod.accessinstance;

/**
 * 多个线程访问同一个实例对象
 *
 * @author Leo
 * @version V1.0
 */
public class MainDemo {

    public static void main(String[] args) {
        test();
    }

    /**
     * 测试场景：多个线程访问同一个实例对象
     *
     * 测试结果：值没有被覆盖，通过对方法加Synchronized关键字做了线程安全的防护
     *
     */
    public static void test() {
        MyService myService = new MyService();

        Thread threadA = new MyThread("a", myService);
        threadA.start();

        Thread threadB = new MyThread("b", myService);
        threadB.start();
    }
}
